Deprecate the nics option from the xm create configuration. Instead, we use the
authoremellor@leeni.uk.xensource.com <emellor@leeni.uk.xensource.com>
Tue, 13 Dec 2005 00:15:53 +0000 (00:15 +0000)
committeremellor@leeni.uk.xensource.com <emellor@leeni.uk.xensource.com>
Tue, 13 Dec 2005 00:15:53 +0000 (00:15 +0000)
entries in vif to guide the configuration.  This is much less confusing.

Closes bug #440.

Change the example configuration files to match.  Also change them to use the
XenSource OUI in the MAC addresses.  Also change xm-test to match.

Remove the obsolete ipaddr configuration entry, and the backend_mac vif config
option.

Remove the preprocess_vifs function, folding it into the configure_vifs
function, and creating a simple comma_sep_kv_to_dict helper.

Remove the configure_vfr method, as it is unused.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
14 files changed:
docs/src/user.tex
tools/examples/xmexample.nbd
tools/examples/xmexample.vmx
tools/examples/xmexample.vti
tools/examples/xmexample1
tools/examples/xmexample2
tools/examples/xmexample3
tools/python/xen/xm/create.py
tools/xm-test/lib/XmTestLib/XenDomain.py
tools/xm-test/tests/create/13_create_multinic_pos.py
tools/xm-test/tests/network/02_network_local_ping_pos.py
tools/xm-test/tests/network/05_network_dom0_ping_pos.py
tools/xm-test/tests/network/11_network_domU_ping_pos.py
tools/xm-test/tests/restore/04_restore_withdevices_pos.py

index 84f5089001764b4c6ca2d310877b367d66b03471..6e958e6075cc1c3f9362ac7b7080b77d910ded00 100644 (file)
@@ -1087,16 +1087,17 @@ for concrete examples.
 \item[vcpus] The number of virtual CPUs. 
 \item[console] Port to export the domain console on (default 9600 +
   domain ID).
-\item[nics] Number of virtual network interfaces.
-\item[vif] List of MAC addresses (random addresses are assigned if not
-  given) and bridges to use for the domain's network interfaces, e.g.\ 
+\item[vif] Network interface configuration.  This may simply contain
+an empty string for each desired interface, or may override various
+settings, e.g.\ 
 \begin{verbatim}
 vif = [ 'mac=00:16:3E:00:00:11, bridge=xen-br0',
         'bridge=xen-br1' ]
 \end{verbatim}
   to assign a MAC address and bridge to the first interface and assign
   a different bridge to the second interface, leaving \xend\ to choose
-  the MAC address.
+  the MAC address.  The settings that may be overridden in this way are
+  type, mac, bridge, ip, script, backend, and vifname.
 \item[disk] List of block devices to export to the domain e.g. 
   \verb_disk = [ 'phy:hda1,sda1,r' ]_ 
   exports physical device \path{/dev/hda1} to the domain as
index 274be6eb06bc8da915a4257f12a83c19f05c58ab..90dadc294d1a0e8981982cce0717efa6a4c4021f 100644 (file)
@@ -12,9 +12,7 @@ kernel = "/boot/vmlinuz-2.6.13-15b-xen"
 ramdisk = "/boot/initrd-2.6.13-15b-xen"
 memory = 128
 name = "nbd4"
-nics=1
-# Please change MAC
-vif = [ 'mac=aa:cc:10:10:00:a0, bridge=xenbr0' ]
+vif = [ '' ]
 # Please change PORT
 disk = [ 'nbd:134.100.233.115 20004,hda1,w' ]
 dhcp = "dhcp"
index 8b694e32feabc5af77a3e082ce3eb736c5efaa23..9030b06117f344bc0c6037db14ef849ded94ccf6 100644 (file)
@@ -37,9 +37,7 @@ vcpus=1
 
 # Optionally define mac and/or bridge for the network interfaces.
 # Random MACs are assigned if not given.
-# nics default is 1
-#vif = [ 'type=ioemu, mac=aa:00:00:00:00:11, bridge=xenbr0' ]
-nics=1 
+#vif = [ 'type=ioemu, mac=00:16:3e:00:00:11, bridge=xenbr0' ]
 # type=ioemu specify the NIC is an ioemu device not netfront
 vif = [ 'type=ioemu, bridge=xenbr0' ]
 
index 5722eb0699f92f9fa0a0aadcc29987061671243e..2daa58ca3936138f2562353916c3d6a57f561346 100644 (file)
@@ -28,12 +28,9 @@ name = "ExampleVMXDomain"
 #cpus = "0"        # all vcpus run on CPU0
 #cpus = "0-3,5,^1" # run on cpus 0,2,3,5
 
-# Disable vif for now
-nics=0
-
 # Optionally define mac and/or bridge for the network interfaces.
 # Random MACs are assigned if not given.
-#vif = [ 'mac=aa:00:00:00:00:11, bridge=xen-br0' ]
+#vif = [ 'mac=00:16:3e:00:00:11, bridge=xen-br0' ]
 
 #----------------------------------------------------------------------------
 # Define the disk devices you want the domain to have access to, and
index 4e7fb4d72f6d4f6d06dced28118ce8b3266a492a..8985ff258211998f412e9c78aa6674ebecb1bb8d 100644 (file)
@@ -33,12 +33,20 @@ name = "ExampleDomain"
 #----------------------------------------------------------------------------
 # Define network interfaces.
 
-# Number of network interfaces. Default is 1.
-#nics=1
+# By default, no network interfaces are configured.  You may have one created
+# with sensible defaults using an empty vif clause:
+#
+# vif = [ '' ]
+#
+# or optionally override backend, bridge, ip, mac, script, type, or vifname:
+#
+# vif = [ 'mac=00:16:3e:00:00:11, bridge=xenbr0' ]
+#
+# or more than one interface may be configured:
+#
+# vif = [ '', 'bridge=xenbr1' ]
 
-# Optionally define mac and/or bridge for the network interfaces.
-# Random MACs are assigned if not given.
-#vif = [ 'mac=aa:00:00:00:00:11, bridge=xenbr0' ]
+vif = [ '' ]
 
 #----------------------------------------------------------------------------
 # Define the disk devices you want the domain to have access to, and
index 6a562a96094ebce1a1fc3c1f133aa6d65ce9f544..ff39c4e7d97e97fa7cc56655809c8496ec9a597d 100644 (file)
@@ -64,12 +64,20 @@ vcpus = 4 # make your domain a 4-way
 #----------------------------------------------------------------------------
 # Define network interfaces.
 
-# Number of network interfaces. Default is 1.
-#nics=1
+# By default, no network interfaces are configured.  You may have one created
+# with sensible defaults using an empty vif clause:
+#
+# vif = [ '' ]
+#
+# or optionally override backend, bridge, ip, mac, script, type, or vifname:
+#
+# vif = [ 'mac=00:16:3e:00:00:11, bridge=xenbr0' ]
+#
+# or more than one interface may be configured:
+#
+# vif = [ '', 'bridge=xenbr1' ]
 
-# Optionally define mac and/or bridge for the network interfaces.
-# Random MACs are assigned if not given.
-#vif = [ 'mac=aa:00:00:00:00:11, bridge=xenbr0' ]
+vif = [ '' ]
 
 #----------------------------------------------------------------------------
 # Define the disk devices you want the domain to have access to, and
index cdb993a2ff936ce50a504214894f219fa34fb514..bf20dd4862090b429b886a48cf05544a20bf7f8e 100644 (file)
@@ -60,9 +60,6 @@ cpus = "%s" % vmid # set based on vmid (mod number of CPUs)
 #----------------------------------------------------------------------------
 # Define network interfaces.
 
-# Number of network interfaces. Default is 1.
-#nics=1
-
 # Optionally define mac and/or bridge for the network interfaces.
 # Random MACs are assigned if not given.
 
index 622bea9b18a5796efba83d2b895c7c7674065ceb..e82ff6cc9195b7c9404a3707a8122bfbb24e0360 100644 (file)
@@ -253,17 +253,12 @@ gopts.var('usb', val='PATH',
           use="""Add a physical USB port to a domain, as specified by the path
           to that port.  This option may be repeated to add more than one port.""")
 
-gopts.var('ipaddr', val="IPADDR",
-          fn=append_value, default=[],
-          use="Add an IP address to the domain.")
-
-gopts.var('vif', val="type=TYPE,mac=MAC,be_mac=MAC,bridge=BRIDGE,script=SCRIPT,backend=DOM,vifname=NAME",
+gopts.var('vif', val="type=TYPE,mac=MAC,bridge=BRIDGE,ip=IPADDR,script=SCRIPT,backend=DOM,vifname=NAME",
           fn=append_value, default=[],
           use="""Add a network interface with the given MAC address and bridge.
           The vif is configured by calling the given configuration script.
           If type is not specified, default is netfront not ioemu device.
           If mac is not specified a random MAC address is used.
-          The MAC address of the backend interface can be selected with be_mac.
           If not specified then the network backend chooses it's own MAC address.
           If bridge is not specified the first bridge found is used.
           If script is not specified the default script is used.
@@ -284,8 +279,10 @@ gopts.var('vtpm', val="instance=INSTANCE,backend=DOM",
           given domain.""")
 
 gopts.var('nics', val="NUM",
-          fn=set_int, default=1,
-          use="""Set the number of network interfaces.
+          fn=set_int, default=-1,
+          use="""DEPRECATED.  Use empty vif entries instead.
+
+          Set the number of network interfaces.
           Use the vif option to define interface parameters, otherwise
           defaults are used. Specifying vifs will increase the
           number of interfaces as needed.""")
@@ -487,58 +484,38 @@ def configure_vtpm(config_devs, vals):
                 config_vtpm.append(['backend', backend])
             config_devs.append(['device', config_vtpm])
 
+
 def configure_vifs(config_devs, vals):
     """Create the config for virtual network interfaces.
     """
+
     vifs = vals.vif
-    vifs_n = max(vals.nics, len(vifs))
-
-    for idx in range(0, vifs_n):
-        if idx < len(vifs):
-            d = vifs[idx]
-            mac = d.get('mac')
-            be_mac = d.get('be_mac')
-            bridge = d.get('bridge')
-            script = d.get('script')
-            backend = d.get('backend')
-            ip = d.get('ip')
-            vifname = d.get('vifname')
-            type = d.get('type')
-        else:
-            mac = None
-            be_mac = None
-            bridge = None
-            script = None
-            backend = None
-            ip = None
-            vifname = None
-            type = None
+    vifs_n = len(vifs)
+
+    if hasattr(vals, 'nics'):
+        if vals.nics > 0:
+            warn("The nics option is deprecated.  Please use an empty vif "
+                 "entry instead:\n\n  vif = [ '' ]\n")
+            for _ in range(vifs_n, vals.nics):
+                vifs.append('')
+            vifs_n = len(vifs)
+        elif vals.nics == 0:
+            warn("The nics option is deprecated.  Please remove it.")
+
+    for c in vifs:
+        d = comma_sep_kv_to_dict(c)
         config_vif = ['vif']
-        if mac:
-            config_vif.append(['mac', mac])
-        if vifname:
-            config_vif.append(['vifname', vifname])
-        if be_mac:
-            config_vif.append(['be_mac', be_mac])
-        if bridge:
-            config_vif.append(['bridge', bridge])
-        if script:
-            config_vif.append(['script', script])
-        if backend:
-            config_vif.append(['backend', backend])
-        if ip:
-            config_vif.append(['ip', ip])
-        if type:
-            config_vif.append(['type', type])
+
+        def f(k):
+            if k not in ['backend', 'bridge', 'ip', 'mac', 'script', 'type',
+                         'vifname']:
+                err('Invalid vif option: ' + k)
+
+            config_vif.append([k, d[k]])
+
+        map(f, d.keys())
         config_devs.append(['device', config_vif])
 
-def configure_vfr(config, vals):
-     if not vals.ipaddr: return
-     config_vfr = ['vfr']
-     idx = 0 # No way of saying which IP is for which vif?
-     for ip in vals.ipaddr:
-         config_vfr.append(['vif', ['id', idx], ['ip', ip]])
-     config.append(config_vfr)
 
 def configure_vmx(config_image, vals):
     """Create the config for VMX devices.
@@ -649,22 +626,6 @@ def preprocess_ioports(vals):
         ioports.append(hexd)
     vals.ioports = ioports
         
-def preprocess_vifs(vals):
-    if not vals.vif: return
-    vifs = []
-    for vif in vals.vif:
-        d = {}
-        a = vif.split(',')
-        for b in a:
-            (k, v) = b.strip().split('=', 1)
-            k = k.strip()
-            v = v.strip()
-            if k not in ['type', 'mac', 'be_mac', 'bridge', 'script', 'backend', 'ip', 'vifname']:
-                err('Invalid vif specifier: ' + vif)
-            d[k] = v
-        vifs.append(d)
-    vals.vif = vifs
-
 def preprocess_vtpm(vals):
     if not vals.vtpm: return
     vtpms = []
@@ -766,12 +727,30 @@ def preprocess(vals):
     preprocess_disk(vals)
     preprocess_pci(vals)
     preprocess_ioports(vals)
-    preprocess_vifs(vals)
     preprocess_ip(vals)
     preprocess_nfs(vals)
     preprocess_vnc(vals)
     preprocess_vtpm(vals)
-         
+
+
+def comma_sep_kv_to_dict(c):
+    """Convert comma-separated, equals-separated key-value pairs into a
+    dictionary.
+    """
+    d = {}
+    c = c.strip()
+    if len(c) > 0:
+        a = c.split(',')
+        for b in a:
+            if b.find('=') == -1:
+                err("%s should be a pair, separated by an equals sign." % b)
+            (k, v) = b.split('=', 1)
+            k = k.strip()
+            v = v.strip()
+            d[k] = v
+    return d
+
+
 def make_domain(opts, config):
     """Create, build and start a domain.
 
index 4ea9c66f93e5a2e78fad7c5359985e503e9fa12b..05ad6b36dc856a751d64b2e1e2d79b8887a22c64 100644 (file)
@@ -203,7 +203,6 @@ class XmTestVmxDomain(XenDomain):
         # Defaults
         self.defaults = {"memory"    : 64,
                          "vcpus"     : 1,
-                         "nics"      : 0,
                          "kernel"    : "/usr/lib/xen/boot/vmxloader",
                          "builder"   : "\'vmx\'",
                          "name"      : name or self.getUniqueName()
@@ -264,7 +263,6 @@ class XmTestPvDomain(XenDomain):
         # Defaults
         self.defaults = {"memory"  : 64,
                          "vcpus"   : 1,
-                         "nics"    : 0,
                          "kernel"  : getDefaultKernel(),
                          "root"    : "/dev/ram0",
                          "name"    : name or self.getUniqueName(),
index 810bf9829c7ba7752cf708e4db6e149d3d562d76..0c5c65946981d8dc9e0d2f618580b9f2699f8dbf 100644 (file)
@@ -6,7 +6,8 @@
 from XmTestLib import *
 
 for i in range(0,10):
-    domain = XmTestDomain(extraOpts={"nics":"%i" % i})
+    domain = XmTestDomain()
+    domain.configSetVar('vif', str(['' for _ in range(0, i)]))
 
     try:
         domain.start()
index a904d49dd909742ec3d62a5046dce9f716f8582d..510711ae23dc33ab298b28ebc5336a67b2c54c40 100644 (file)
@@ -28,7 +28,7 @@ ip   = Net.ip("dom1", "eth0")
 mask = Net.mask("dom1", "eth0")
 
 # Fire up a guest domain w/1 nic
-domain = XmTestDomain(extraOpts={ 'nics' : 1 })
+domain = XmTestDomain()
 try:
     domain.configSetVar('vif', " [ 'ip=" + ip + "' ]")
     domain.start()
index b252c2d3edd9ba7beab62fae21871127f4f84919..84e6be058a0267cdb03b4f7607f55638616e82ba 100644 (file)
@@ -31,7 +31,7 @@ except NetworkError, e:
         FAIL(str(e))
 
 # Fire up a guest domain w/1 nic
-domain = XmTestDomain(extraOpts={ 'nics' : 1 })
+domain = XmTestDomain()
 try:
     domain.configSetVar('vif', " [ 'ip=" + ip + "' ]")
     domain.start()
index ca3fe3579322bcc9c5f90bb0b5e81929f26c6b9f..5ac80215627fbee60e1dbe5bab62b32984febfc6 100644 (file)
@@ -21,7 +21,7 @@ from XmTestLib import *
 
 
 def netDomain(ip):
-    dom = XmTestDomain(extraOpts={ 'nics' : 1 })
+    dom = XmTestDomain()
     try:
         dom.configSetVar('vif', " [ 'ip=" + ip + "' ]")
         dom.start()
index 0b82943142b605087b81ffc8e3a15e8098afdc5b..af290f4b8b9329f1f0395a12b9bf9ffaf9fe40d4 100644 (file)
@@ -7,7 +7,9 @@ from XmTestLib import *
 
 import re
 
-domain = XmTestDomain(extraOpts={"nics":2})
+domain = XmTestDomain()
+
+domain.configSetVar('vif', "[ '', '' ]")
 
 domain.configAddDisk("phy:/dev/ram0", "hda1", "w")
 domain.configAddDisk("phy:/dev/ram1", "hdb2", "w")